﻿using System;
using System.IO;

namespace Gonte.Utilities
{
    public static class DirectoryHelper
    {
        public static void CopyDirectory(string source, string destination)
        {
            CopyDirectory(new DirectoryInfo(source), new DirectoryInfo(destination));
        }

        public static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
        {
            // Check if the target directory exists, if not, create it.
            if (!Directory.Exists(destination.FullName))
            {
                Directory.CreateDirectory(destination.FullName);
            }

            // Copy each file into it’s new directory.
            foreach (FileInfo fileInfo in source.GetFiles())
            {
                fileInfo.CopyTo(Path.Combine(destination.ToString(), fileInfo.Name), true);
            }

            // Copy each subdirectory using recursion.
            foreach (DirectoryInfo subDirectory in source.GetDirectories())
            {
                DirectoryInfo subDirectoryClone = destination.CreateSubdirectory(subDirectory.Name);
                CopyDirectory(subDirectory, subDirectoryClone);
            }
        }
    }
}
